package com.qyhl.webtv.module_news.news.information.info;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.SectionBean;
import com.qyhl.webtv.module_news.common.NewsUrl;

import java.util.List;

/**
 * Created by qyhl on 2017/11/28.
 */

public class InformationModel implements InformationContract.InformationModel {
    private InformationPresenter mPresenter;

    public InformationModel(InformationPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 获取所有栏目
     *
     * @param id
     * @param type
     */
    @Override
    public void getData(String id, String type) {

        EasyHttp.get(NewsUrl.GET_MENU_LIST)
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("menuId", id)
                .params("menuType", type)
                .execute(new SimpleCallBack<List<SectionBean>>() {

                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError(2, "暂无任何内容！");
                        } else {
                            mPresenter.setError(1, "解析出错，数据加载失败！");
                        }
                    }

                    @Override
                    public void onSuccess(List<SectionBean> sectionBeans) {
                        if (sectionBeans != null && sectionBeans.size() > 0) {
                            mPresenter.setData(sectionBeans);
                        } else {
                            mPresenter.setError(2, "暂无任何内容！");
                        }
                    }
                });

    }
}
